//
// DRV8311P.H
// Created by Xiaoyun on 2023/3/22.
//

#ifndef FOC_DRV8311P_H
#define FOC_DRV8311P_H

#include <stdint.h>
#include "drv8311_reg.h"
#include "drv8311p_config.h"




/*------------------------------User Interface Function------------------------------*/

void DRV_Init();

void DRV_Mean_Cal();

uint16_t DRV_Get_ADC(DRV_Channel_ADC channel);

void DRV_ADC_Start();

void DRV_ADC_Stop();

uint16_t DRV_Get_REG(DRV_REGS_ADDR_e addr, uint8_t device_id);

void DRV_Get_STS_Datas(DEV_STS1_t *dev_sts, OT_STS_t *ot_sts, SUP_STS_t *sup_sts, DRV_STS_t *drv_sts,
                  SYS_STS_t *sys_sts, uint8_t device_id);

void DRV_Set_FLT_MODE(FLT_MODE_t *flt_mode, uint16_t device_id);

void DRV_Set_SYSF_CTRL(SYSF_CTRL_t *sysf_ctrl, uint16_t device_id);

void DRV_Set_DRVF_CTRL(DRVF_CTRL_t *drvf_ctrl, uint16_t device_id);

void DRV_Set_FLT_TCTRL(FLT_TCTRL_t *flt_tctrl, uint16_t device_id);

void DRV_FLT_Clear(uint16_t device_id);

void DRV_Set_PWMG_Period(uint16_t pwmg_period, uint16_t device_id);

void DRV_Set_PWMG_Duty(uint16_t pwmg_A_duty, uint16_t pwmg_B_duty, uint16_t pwmg_C_duty, uint16_t device_id);

void DRV_Set_PWMG_Duty_State(uint16_t pwmg_A_duty, uint16_t pwmg_B_duty, uint16_t pwmg_C_duty,PWM_STATE_t* pwm_state, uint16_t device_id);

void DRV_Set_PWM_STATE(PWM_STATE_t *pwm_state, uint16_t device_id);

void DRV_Set_PWMG_CTRL(PWMG_CTRL_t *pwmg_ctrl, uint16_t device_id);

void DRV_Set_PWM_CTRL1(PWM_CTRL1_t *pwm_ctrl1, uint16_t device_id);

void DRV_Set_DRV_CTRL(DRV_CTRL_t *drv_ctrl, uint16_t device_id);

void DRV_Set_CSA_CTRL(CSA_CTRL_t *csa_ctrl, uint16_t device_id);

void DRV_Set_SYS_CTRL(SYS_CTRL_t *sys_ctrl, uint16_t device_id);

/*------------------------------Weak Function(User to implement)------------------------------*/

void DRV_ADC_DMA_Init(uint16_t *adc_dma_buff, uint8_t dma_buff_size);

void DRV_PWM_Init();

void DRV_SPI_Init();

void DRV_tSPI_TransmitReceive(uint16_t *drv_write_buff, uint16_t *drv_read_buff, uint8_t num);

void DRV_ADC_Start_DMA(uint16_t *adc_dma_buff, uint8_t dma_buff_size);

void DRV_ADC_Stop_DMA();
#endif //FOC_DRV8311P_H
